package calao.plan;

import calao.storage.Record;

/** Task pools used for automatic scheduling purpose.
 */
public class SchedulePool {

	/** Unscheduled tasks.
	 * Tasks are left unscheduled when they are not assigned to any resource, or when 
	 * their work time is not specified.
	 */ 
	public static final int UNSCHEDULED = 0;
	
	/** Automatically-scheduled tasks that are <em>not</em> started yet.
	 */
	public static final int SCHEDULED = 1;

	/** Automatically-scheduled <em>started</em> tasks.
	 * Contains tasks scheduled by the system and marked as started by user. Such tasks
	 * have a fixed start date and a floating end date.
	 */
	public static final int STARTED = 2;

	/** Fixed tasks still taken into account for planning purpose.
	 */
	public static final int FIXED = 3;
	
	static final int FIRST_POOL = UNSCHEDULED;
	
	static final int LAST_POOL = FIXED;
	
	public static void setPool(Record taskRecord, int pool)
	{
		for (Integer tpool : TaskDB.getPools(taskRecord)) {
			if (tpool==pool) return;
			if (isValidPool(tpool)) TaskDB.removePool(taskRecord, tpool);
		}
		TaskDB.addPool(taskRecord, pool);
	}

	public static int getPool(Record taskRecord)
	{
		for (Integer tpool : TaskDB.getPools(taskRecord)) {
			if (isValidPool(tpool)) return tpool;
		}
		return -1;
	}
	
	static boolean isValidPool(int pool)
	{
		return (pool>=UNSCHEDULED && pool<=FIXED);
	}
	
}
